<?php

    function sql_select(){
        //connect
        $link = mysql_pconnect('localhost', 'bothost', 'fishballs')
            OR die(mysql_error());
        // get all args passed in
        $arg_list = func_get_args();
        // the first element is the query
        $sql = array_shift($arg_list);
        // apply mysql_real_escape_string to every argument
        foreach ($arg_list as &$value) {
            $value = mysql_real_escape_string($value);
        }
        // apply sprintf with array
        $query = vsprintf($sql,$arg_list);
        //select the DB
        mysql_select_db("bothost");
        // do query
        $result = mysql_query($query)
            OR die(mysql_error());
        
        //loop what we get back
        $rows = array();
        while ($row = mysql_fetch_assoc($result)) {
            $rows[] = $row;
        }
        //free the mem
        mysql_free_result($result);
        return $rows;
    }
    
?>
